home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 6: Level 6 / 17 Bit - Level 6 (1998)(Epic Marketing)[!].iso / quartz / q0155.dms / q0155.adf / arppro3 / fmalloc.c < prev    next >
C/C++ Source or Header  |  1991-04-16  |  2KB  |  87 lines

  1. /* fmalloc.c */
  2.  
  3. #include <exec/memory.h>
  4. #include <libraries/arpbase.h>
  5. #include <functions.h>
  6.  
  7. /* !!! could add a magic # to this to make free() more robust */
  8. struct mem {
  9.     struct DefaultTracker *tracker;
  10. };
  11.  
  12.  
  13. /*doc fmalloc
  14. NAME
  15.     fmalloc -- arp'd fmalloc()
  16.  
  17. SYNOPSIS
  18.     result = fmalloc(size,flags)
  19.  
  20.     void *result;
  21.     unsigned long size,flags;
  22.  
  23. FUNCTION
  24.     Allocates memory using Amiga memory flags (defined in
  25.     <exec/memory.h>).  Memory allocated this way can later be freed by
  26.     calling free().  These allocations use Arp resource tracking an
  27.     therefore will be freed by ArpExit().
  28.  
  29. INPUTS
  30.     size - number of bytes to allocate
  31.     flags - memory (MEMF_) flags
  32.  
  33. RESULTS
  34.     result - pointer to memory block or NULL on failure
  35.  
  36. SEE ALSO
  37.     malloc(), free(), fmalloc()
  38.  
  39. MODULE
  40.     fmalloc.c
  41. *end */
  42.  
  43. void *fmalloc(size,flags)
  44. unsigned long size,flags;
  45. {
  46.     register struct mem *mp;
  47.  
  48.     if (!(mp = ArpAllocMem(size+sizeof(struct mem), flags))) return NULL;
  49.  
  50.     mp->tracker = LastTracker;
  51.  
  52.     return (char *)mp + sizeof(struct mem);
  53. }
  54.  
  55. void *lmalloc(size)
  56. unsigned long size;
  57. {
  58.     return fmalloc (size,0L);
  59. }
  60.  
  61. void *calloc (nelem,size)
  62. unsigned nelem, size;
  63. {
  64.     return fmalloc ((unsigned long)nelem * size,MEMF_CLEAR);
  65. }
  66.  
  67. void *lcalloc (nelem,size)
  68. unsigned long nelem, size;
  69. {
  70.     return fmalloc (nelem * size,MEMF_CLEAR);
  71. }
  72.  
  73. void *malloc(size)
  74. unsigned size;
  75. {
  76.     return fmalloc ((unsigned long)size,0L);
  77. }
  78.  
  79. free(blk)
  80. char *blk;
  81. {
  82.     register struct mem *mp = (void *)(blk - sizeof(struct mem));
  83.  
  84.     FreeTrackedItem (mp->tracker);
  85.     return 0;
  86. }
  87.